<?php
	include 'include/conf.php';
	$admin_info = $db->selectAll('admin', 'admin_name');
	$names = [];
	foreach($admin_info as $val){
		$names[] = $val['admin_name'];
	}

	if(!empty($_POST['create'])){
		if(in_array($_POST['username'], $names)){
			echo "<script>alert('用户已存在！');window.location.href='user_add.php'</script>";
			return;
		}
		$new_admin = $_POST['username'];
		$new_pwd = md5($_POST['password']);
		$create_time = time();
		$ip = $_SERVER['REMOTE_ADDR'];


		$arr = [
			'admin_name' => $new_admin,			
			'admin_pwd' => $new_pwd,			
			'admin_last_login' => $create_time,			
			'admin_reg_time' => $create_time,			
			'admin_reg_ip' => $ip		
		];
		if($db->insert('admin', $arr)['msg'] == '添加成功!'){
			echo "<script>alert('注册成功！');</script>";
			$login->login('create');
			echo "<script>window.location.href='index.php';</script>";
		}
	}

?>
<!DOCTYPE html>
<html lang="zxx">
<!-- Head -->

<head>
    <title>Key Login Form Flat Responsive Widget Template :: W3layouts</title>
    <!-- Meta-Tags -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="utf-8">
	<meta name="keywords" content="Key Login Form a Responsive Web Template, Bootstrap Web Templates, Flat Web Templates, Android Compatible Web Template, Smartphone Compatible Web Template, Free Webdesigns for Nokia, Samsung, LG, Sony Ericsson, Motorola Web Design">

	
    <script>
        addEventListener("load", function () {
            setTimeout(hideURLbar, 0);
        }, false);

        function hideURLbar() {
            window.scrollTo(0, 1);
        }
    </script>
    <!-- //Meta-Tags -->
    <!-- Index-Page-CSS -->
    <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
    <!-- //Custom-Stylesheet-Links -->
    <!--fonts -->
    <!-- //fonts -->
    <link rel="stylesheet" href="css/font-awesome.min.css" type="text/css" media="all">
    <!-- //Font-Awesome-File-Links -->
	
	<!-- Google fonts -->
	<link href="//fonts.googleapis.com/css?family=Quattrocento+Sans:400,400i,700,700i" rel="stylesheet">
	<link href="//fonts.googleapis.com/css?family=Mukta:200,300,400,500,600,700,800" rel="stylesheet">
	<!-- Google fonts -->

</head>
<!-- //Head -->
<!-- Body -->

<body>

<section class="main">
	<div class="layer">
		
		<div class="bottom-grid">
			<div class="logo">
				<h1> <a href="index.php"><span class="fa fa-key"></span> Key</a></h1>
			</div>
			<div class="links">
				<ul class="links-unordered-list">
					<li class="active">
						<a href="login.php" class="">Login</a>
					</li>
				</ul>
			</div>
		</div>
		<div class="content-w3ls">
			<div class="text-center icon">
				<span class="fa fa-html5"></span>
			</div>
			<div class="content-bottom">
				<form action="" method="post">
					<div class="field-group">
						<span class="fa fa-user" aria-hidden="true"></span>
						<div class="wthree-field">
							<input name="username" id="text1" type="text" placeholder="Username" required>
						</div>
					</div>
					<div class="field-group">
						<span class="fa fa-lock" aria-hidden="true"></span>
						<div class="wthree-field">
							<input name="password" id="myInput" type="Password" placeholder="Password">
						</div>
					</div>
					<div class="field-group">
						<span class="fa fa-lock" aria-hidden="true"></span>
						<div class="wthree-field">
							<input name="password_again" id="myInput" type="Password" placeholder="Confirm-Password">
						</div>
					</div>
					<div class="wthree-field">
						<button type="submit" name="create" class="btn" value="创建">Get Started</button>
					</div>
					<!-- <ul class="list-login">
						<li class="switch-agileits">
							<label class="switch">
								<input type="checkbox">
								<span class="slider round"></span>
								keep Logged in
							</label>
						</li>
						<li class="clearfix"></li>
					</ul> -->
					<!-- <ul class="list-login-bottom">
						<li class="">
							<a href="#" class=""></a>
						</li>
						<li class="">
							<a href="#" class="text-right">Need Help?</a>
						</li>
						<li class="clearfix"></li>
					</ul> -->
				</form>
			</div>
		</div>
		<div class="bottom-grid1">
			<div class="links">
				<ul class="links-unordered-list">
					<li class="">
						<a href="#" class="">About Us</a>
					</li>
					<li class="">
						<a href="#" class="">Privacy Policy</a>
					</li>
					<li class="">
						<a href="#" class="">Terms of Use</a>
					</li>
				</ul>
			</div>
			<div class="copyright">
				<p>© 2019 Key. All rights reserved | Design by
					<a href="http://w3layouts.com">W3layouts</a>
				</p>
			</div>
		</div>
    </div>
</section>

</body>
<!-- //Body -->
</html>
